package com.gitee.wsl.compose.mvi.ui.dropdown.menu

import androidx.compose.material3.DropdownMenu
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.PopupProperties
import com.gitee.wsl.compose.mvi.component.Projector
import com.gitee.wsl.compose.mvi.ui.iconbutton.IconButtonProjector


class DropdownMenuProjector(
    interactor: DropdownMenuInteractor,
    presenter: DropdownMenuPresenter = DropdownMenuPresenter.Default
) : Projector<DropdownMenuInteractor, DropdownMenuPresenter>(interactor, presenter) {

    /*@Composable
    fun Projection(
        modifier: Modifier = Modifier,
    ) = contextualize(modifier) { combinedModifier, interactor, presenter ->
        val iconProjectors = interactor.icons.map { IconButtonProjector(it, presenter.icon) }

        DropdownMenu(
            expanded = interactor.expanded,
            onDismissRequest = interactor.onDismissRequest,

            // TODO add rest of popup properties
            properties = PopupProperties(focusable = interactor.focusable),
            modifier = combinedModifier,
            offset = presenter.offset,
        ) {
            iconProjectors.forEach { icon -> icon.Projection() }
        }
    }*/

    @Composable
    override fun body(
        combinedModifier: Modifier,
        interactor: DropdownMenuInteractor,
        presenter: DropdownMenuPresenter,
    ) {
        val iconProjectors = interactor.icons.map { IconButtonProjector(it, presenter.icon) }

        DropdownMenu(
            expanded = interactor.expanded,
            onDismissRequest = interactor.onDismissRequest,

            // TODO add rest of popup properties
            properties = PopupProperties(focusable = interactor.focusable),
            modifier = combinedModifier,
            offset = presenter.offset,
        ) {
            iconProjectors.forEach { icon -> icon() }
        }
    }
}